#ifndef __OS_API__
#define __OS_API__
#include "os_include.h"

#if defined(__FreeRTOS__)
typedef     QueueHandle_t  queue_msg_t;
typedef     TaskHandle_t   task_handle_t;
#define	   INVALID_TASK		NULL

typedef     SemaphoreHandle_t   semaphore_handle_t;
typedef     SemaphoreHandle_t    mutex_handle_t;
typedef    EventGroupHandle_t    event_handle_t;

typedef    TimerHandle_t         timer_handle_t;

typedef    TickType_t          tick_timeout_t;

#elif defined(__RTT_OS__)

typedef	   rt_mq_t  		queue_msg_t;
typedef	   rt_thread_t    task_handle_t;
#define	   INVALID_TASK		NULL
typedef    rt_sem_t     semaphore_handle_t;
typedef    rt_mutex_t   mutex_handle_t;
typedef    rt_event_t    event_handle_t;

typedef    rt_timer_t         timer_handle_t;

typedef    rt_int32_t          tick_timeout_t;

#elif defined(__LINUX_OS__)
typedef	   mqd_t 		queue_msg_t;
typedef	   pthread_t  	task_handle_t;
#define	   INVALID_TASK		0

typedef    sem_t *semaphore_handle_t;
typedef    pthread_mutex_t   *mutex_handle_t;
typedef    void    event_handle_t;

typedef    void         timer_handle_t;

typedef    long          tick_timeout_t;

#define ACPI_MSEC_PER_SEC               1000L

#define ACPI_USEC_PER_MSEC              1000L
#define ACPI_USEC_PER_SEC               1000000L

#define ACPI_NSEC_PER_USEC              1000L
#define ACPI_NSEC_PER_MSEC              1000000L
#define ACPI_NSEC_PER_SEC               1000000000L

#else

#error " os ?"

#endif



#define  OS_EVENT_0			(1 << 0)
#define  OS_EVENT_1			(1 << 1)
#define  OS_EVENT_2			(1 << 2)
#define  OS_EVENT_3			(1 << 3)
#define  OS_EVENT_4			(1 << 4)
#define  OS_EVENT_5			(1 << 5)
#define  OS_EVENT_6			(1 << 6)
#define  OS_EVENT_7			(1 << 7)
#define  OS_EVENT_8			(1 << 8)
#define  OS_EVENT_9			(1 << 9)


#include "msgqueue_v2.h"
#include "my_events.h"
#include "os_timer.h"
#include "sleep_fun.h"


extern semaphore_handle_t  os_semaphore_create(const char *pname);
extern int os_semaphore_delete(semaphore_handle_t sem);

extern int os_semaphore_take(semaphore_handle_t sem);
extern int os_semaphore_try_take(semaphore_handle_t sem);
extern int os_semaphore_take_waitTick(semaphore_handle_t sem,tick_timeout_t tick);


extern int os_semaphore_release(semaphore_handle_t sem);
extern int os_semaphore_release_from_isr(semaphore_handle_t sem);



extern mutex_handle_t  os_mutex_create(const char *pname);
extern int os_mutex_delete(mutex_handle_t mutex);

extern int os_mutex_take(mutex_handle_t mutex);
extern int os_mutex_try_take(mutex_handle_t mutex);

extern int os_mutex_release(mutex_handle_t mutex);

extern task_handle_t os_task_create(const char *name,
                             void (*entry)(void *parameter),
                             void       *parameter,
                             uint32_t stack_size,
                             uint8_t  priority,
                             uint32_t tick);
extern int os_task_delete(task_handle_t *ptask);

extern int os_task_delete_for_name(char * pname);
extern task_handle_t os_task_find_for_name(char * pname);
extern task_handle_t os_task_getself(void);
extern int os_task_join(task_handle_t task);
extern int os_task_detach(task_handle_t task);



#endif
